package com.springboot.ball.consumer.games;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
    private Integer id;
    private double x;
    private double y;
    private double radius;
    private double speed;
    private boolean isMe;
    private List<Integer> steps;
    private double vx; // 新增速度分量
    private double vy;
    private double health; // 添加生命值属性

    // 构造函数需要添加health参数
    public Player(Integer id, double x, double y, double radius, double speed, boolean isMe, List<Integer> steps, double vx, double vy) {
        this.id = id;
        this.x = x;
        this.y = y;
        this.radius = radius;
        this.speed = speed;
        this.isMe = isMe;
        this.steps = steps;
        this.vx = vx;
        this.vy = vy;
        this.health = 100; // 初始生命值为100
    }

    // 更新位置的方法
    public void updatePosition() {
        x += vx;
        y += vy;
    }
    
    // 受到伤害
    public void takeDamage(double damage) {
        this.health -= damage;
    }
    
    // 检查是否存活
    public boolean isAlive() {
        return health > 0;
    }
}
